/*
 * Copyright (c) 2018-2999 九五云信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.distribution.platform.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.config.Constant;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.distribution.comment.model.DistributionUserBan;
import com.yami.shop.distribution.comment.service.DistributionUserBanService;
import com.yami.shop.security.platform.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author lgh on 2019/04/01.
 */
@RestController
@RequestMapping("/distribution/distributionUserBan")
public class DistributionUserBanController {

    @Autowired
    private DistributionUserBanService distributionUserBanService;

    /**
     * 分页获取
     */
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserBan:page')")
    public ResponseEntity<IPage<DistributionUserBan>> page(DistributionUserBan distributionUserBan, PageParam<DistributionUserBan> page) {
        IPage<DistributionUserBan> list = distributionUserBanService.page(page, new LambdaQueryWrapper<DistributionUserBan>());
        return ResponseEntity.ok(list);
    }

    /**
     * 分页获取
     */
    @GetMapping("/page/anduser")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserBan:page')")
    public ResponseEntity<IPage<DistributionUserBan>> page(DistributionUserBan distributionUserBan, String userMobile, PageParam<DistributionUserBan> page) {
        IPage<DistributionUserBan> list = distributionUserBanService.distributionUserBanPage(page, Constant.PLATFORM_SHOP_ID, userMobile, distributionUserBan);
        return ResponseEntity.ok(list);
    }

    /**
     * 获取信息
     */
    @GetMapping("/info/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserBan:info')")
    public ResponseEntity<DistributionUserBan> info(@PathVariable("id") Long id) {
        DistributionUserBan distributionUserBan = distributionUserBanService.getById(id);
        return ResponseEntity.ok(distributionUserBan);
    }

    /**
     * 保存
     */
    @PostMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserBan:save')")
    public ResponseEntity<Void> save(@RequestBody @Valid DistributionUserBan distributionUserBan) {
        distributionUserBanService.save(distributionUserBan);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改
     */
    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserBan:update')")
    public ResponseEntity<Void> update(@RequestBody @Valid DistributionUserBan distributionUserBan) {
        distributionUserBanService.updateById(distributionUserBan);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserBan:delete')")
    public ResponseEntity<Void> delete(@PathVariable Long id) {
        distributionUserBanService.removeById(id);
        return ResponseEntity.ok().build();
    }
}
